package com.thread.www.demo;

/**
 * Created by 27340 on 2017/11/25.
 */
public class SycronizedDemo {

    public static class Demo{
        public  void a(){
            synchronized(Demo.class){
                System.out.println("in a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        public void b(){
            synchronized(Demo.class){
                System.out.println("in b");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public static void main(String[] args) {
//        final Demo d = new Demo();
        final Demo d1 = new Demo();
        final Demo d2 = new Demo();
        Thread t1 = new Thread(new Runnable(){
            @Override
            public void run() {
                d1.a();
            }
        });

        Thread t2 = new Thread(new Runnable(){
            @Override
            public void run() {
                d2.b();
            }
        });
        t1.start();
        t2.start();

    }
}
